package ink.lovejinhu.leetcode;

/**
 * @author jinhu
 * created 2021-06-29 11:01
 */
public class Solution_0125 {
    /**
     * 判断是否是回文
     * @param s
     * @return
     */
    public boolean isPalindrome(String s) {
        if (s == null || s.trim().equals("")) {
            return true;
        }
        s = s.toLowerCase();
        System.out.println(s);
        char[] chars = s.toCharArray();
        StringBuilder res = new StringBuilder();
        for (int i = 0; i < chars.length; i++) {
            if ((chars[i] >= 'A' && chars[i] <= 'Z') || (chars[i] >= 'a' && chars[i] <= 'z')||(chars[i]>='0'&&chars[i]<='9')) {
                res.append(chars[i]);
            }
        }
        char[] chars1 = res.toString().toCharArray();
        int left = 0;
        int right = chars1.length - 1;
        for (; left<=right; ) {
            if (chars1[left]!=chars1[right]){
             return false;
            }
            left++;
            right--;
        }
        return true;
    }

    public static void main(String[] args) {
        String temp="0P";
        Solution_0125 solution_0125 = new Solution_0125();
        System.out.println(solution_0125.isPalindrome(temp));
    }
}
